package org.alvin;

import io.netty.buffer.ByteBufUtil;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) throws IOException {

        try   {
            Socket socket = new Socket("localhost", 9999);
            new Thread() {
                @Override
                public void run() {
                    try {
                        InputStream in = socket.getInputStream();
                        byte[] buff = new byte[1024];
                        int len = 0;
                        while ((len = in.read(buff)) != 0) {
                            ByteArrayOutputStream out = new ByteArrayOutputStream();
                            out.write(buff, 0, len);
                            System.out.println(ByteBufUtil.hexDump(out.toByteArray()));
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
            }.start();
            // 发送消息到服务器
            String text = "444E5910003B37AB0401002198080200000905EE02";
            byte[] buff = ByteBufUtil.decodeHexDump(text);
            socket.getOutputStream().write(buff);
            socket.getOutputStream().flush();


//            text = "444E5913003B37AB04B900207E00021421000000E4009104";
//            buff = ByteBufUtil.decodeHexDump(text);
//            socket.getOutputStream().write(buff);
//            socket.getOutputStream().flush();


        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
